<?php

if (! defined('SIMPLE_TEST')) {
    define('SIMPLE_TEST', '../simpletest/');
}
require_once(SIMPLE_TEST . 'autorun.php');

require_once '../Sql/DBInstalacionDAO.php';
require_once '../Sql/conexion.php';
require_once '../Sql/claseDB.php';
require_once '../Exception/CustomException.php';
require_once '../Class/Instalacion.php';


class DBInstalacionDAOTest extends UnitTestCase {

    function DBInstalacionDAOTest() {
        $this->UnitTestCase();
    }

     public function testgetNombre() {
        $DBInstalacionDAOTest = new DBInstalacionDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_suministro_instalacion
                            VALUES (-1, 'Prueba Instalacion', 1,
                            1, 1)" );

        $Nombre = $DBInstalacionDAOTest->getNombre( -1 );
        $this->assertEqual( $Nombre, 'Prueba Instalacion' );
        $DBConn->consulta( "DELETE FROM costo_suministro_instalacion
                          WHERE CSI_ID = -1" );
     }

      public function testgetTipo() {
        $DBInstalacionDAOTest = new DBInstalacionDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_suministro_instalacion
                            VALUES (-1, 'Prueba Instalacion', 1,
                            1, 1)" );

        $Tipo = $DBInstalacionDAOTest->getTipo( -1 );
        $this->assertEqual( $Tipo, 1 );
        $DBConn->consulta( "DELETE FROM costo_suministro_instalacion
                          WHERE CSI_ID = -1" );

      }

      public function testsetInstalacion() {
        $DBInstalacionDAOTest = new DBInstalacionDAO();
        $miInstalacion = new Instalacion( 'Prueba Instalacion', 10, 1, 2);
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO presupuesto
                           VALUES (-1, 'PRESUPUESTO',
                           '2010-06-04', NULL, NULL,
                           NULL, 1, 1)" );


        $DBInstalacionDAOTest->setInstalacion( $miInstalacion, -1);
        $DBConn->consulta( "SELECT *
                            FROM suministro_instalacion
                            WHERE SIN_NOMBRE = 'Prueba Instalacion'
                            AND SIN_PRECIO = 10
                            AND SIN_CANTIDAD = 2
                            AND SIN_TIPO = 1
                            AND SIN_STATUS = 1
                            ORDER BY SIN_ID DESC " );

        $fila = $DBConn->extraer_registro();
        $id = $fila['SIN_ID'];
        $this->assertEqual( $fila['SIN_NOMBRE'], 'Prueba Instalacion' );
        $this->assertEqual( $fila['SIN_PRECIO'], 10 );
        $this->assertEqual( $fila['SIN_CANTIDAD'], 2 );
        $this->assertEqual( $fila['SIN_TIPO'], 1 );

        $DBConn->consulta( "SELECT *
                            FROM detalle_presupuesto
                            WHERE DPR_PTO_ID = -1" );

        $fila = $DBConn->extraer_registro();
        $this->assertEqual( $fila['DPR_PTO_ID'], -1 );
        $this->assertEqual( $fila['DPR_SIN_ID'], $id );
        $DBConn->consulta( "DELETE FROM detalle_presupuesto
                            WHERE DPR_SIN_ID = $id
                            AND DPR_PTO_ID = -1" );

        $DBConn->consulta( "DELETE FROM presupuesto
                            WHERE PTO_ID = -1" );

        $DBConn->consulta( "DELETE FROM suministro_instalacion
                            WHERE SIN_ID = $id" );
      }
}
?>

